/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package op;

import core.CreateConta;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Jônatas
 */
public class CreateContaClaro implements CreateConta {

    public ContaTelefonica createConta(String[] fullFile) throws Exception {

        ContaTelefonica contaTelefonica = new ContaTelefonica();

        Map<String, Object> parametersMap = new HashMap<String, Object>();

        contaTelefonica.contaMensal = new ArrayList<EntradaAbstrata>();
        boolean first = true;

        for (String line : fullFile) {

            line = line.trim();

            if (line.isEmpty()) {
                continue;
            }

            line += " ";

            String[] dados = line.split(";");

            if (dados.length == 14) {
                if (first) {
                    first = false;
                    continue;
                }
                parametersMap.put("dados", dados);
                EntradaAbstrata entrada = new QuebraStringClaro().quebraString(parametersMap);
                if (entrada != null) {
                    contaTelefonica.contaMensal.add(entrada);
                }
            }
        }

        Collections.sort(contaTelefonica.contaMensal, new ComparatorEntradaAbstrataPorTelefone());

        contaTelefonica.contaResumida();

        return contaTelefonica;

    }
}
